//
//  InterViewSkillAPIManger.m
//  FindJob
//
//  Created by apple on 16/3/8.
//  Copyright © 2016年 Lee. All rights reserved.
//

#import "InterViewSkillAPIManger.h"
#import "NetWorkingConfig.h"

@implementation InterViewSkillAPIManger

- (void)startInterViewSkillRequestWithPaprameters:(NSDictionary *)parameter responds:(void (^)(RespondsStatus, NSString *, id))respondsBlock{
    [self startRequestURL:kInterSkillURL parameters:parameter success:^(id responds) {
        NSInteger resultCode = [responds[@"resultCode"] integerValue];
        NSString *resultDesc = responds[@"resultDesc"];
        id resultData = responds[@"techniquess"];
        
        
        NSMutableArray *companyNames = [[NSMutableArray alloc] init];
        
        for (int i = 0; i < [resultData count]; i++) {
            
            NSString *companyName = resultData[i][@"techniquesType"];
            if (![companyNames containsObject:companyName]) {
                [companyNames addObject:companyName];
            }
        }
        
        NSMutableDictionary *resultDict = [[NSMutableDictionary alloc] init];
        for(int i = 0 ; i < [companyNames count];i++) {
            NSMutableArray *infoArr = [NSMutableArray array];
            for (int j = 0; j < [resultData count]; j++) {
                NSString *name = resultData[j][@"techniquesType"];
                if ([name isEqualToString:companyNames[i]]) {
                    [infoArr addObject:resultData[j]];
                }
            }
            [resultDict setObject:infoArr forKey:companyNames[i]];
        }
     
     
     if (resultCode == 0) {
            if (respondsBlock) {
                respondsBlock(RespondsStatusSuccess,resultDesc,resultDict);
            }else{
                if (respondsBlock) {
                    respondsBlock(RespondsStatusDataError,resultDesc,resultDict);
                }
            }
        }
    } failure:^(NSError *error) {
        if (respondsBlock) {
            respondsBlock(RespondsStatusNotworkingError,@"网络错误",nil);
        }
    } timeout:30];
}

- (void)startInterViewSkillDetailRequestWithPaprameters:(NSDictionary *)parameter responds:(void (^)(RespondsStatus, NSString *, id))respondsBlock{
    [self startRequestURL:kInterViewDetailURL parameters:parameter success:^(id responds) {
        NSInteger resultCode = [responds[@"resultCode"] integerValue];
        NSString *resultDesc = responds[@"resultDesc"];
        id resultData = responds[@"techniquesExts"];
        
        
        if (resultCode == 0) {
            if (respondsBlock) {
                respondsBlock(RespondsStatusSuccess,resultDesc,resultData);
            }else{
                if (respondsBlock) {
                    respondsBlock(RespondsStatusDataError,resultDesc,resultData);
                }
            }
        }

    } failure:^(NSError *error) {
        if (respondsBlock) {
            respondsBlock(RespondsStatusNotworkingError,@"网络错误",nil);
        }
    } timeout:30];
}
@end
